var vows = require('vows'),
    assert = require('assert'),
    _ = require('underscore'),
    path = require('path');

require.paths.unshift(path.join(__dirname, '../..', 'services'));  //add services to require.paths
var subscribeService = require('subscribeService');

var user_id = 123456;
//var filter = {"industry": ["computer", "web"], "jobtitle": ["dev", "qa"], "location": ["Shanghai", "Beijing"], "salary": {"value": "5000", "op": ">="}, "company": [{"value": "google", "op": "like"}, {"value": "sina", "op": "eq"}], "type": ["full time", "part time"]};
var filter = {"industry": ["计算机", "互联网"], "jobtitle": ["软件研发", "软件测试"], "location": ["上海", "北京"], "salary": {"value": "5000", "op": ">="}, "company": [{"value": "网易", "op": "like"}, {"value": "新浪", "op": "eq"}], "type": ["全职", "兼职"]};

vows.describe('test SubscribeService').addBatch({
    'subscribeService.subscribeTopic: success' : {
        topic : function() {
            subscribeService.subscribeTopic(user_id, filter, this.callback);
        },

        'subscribe success' : function(err, result, filter) {
            assert.equal(result.status, 'success');
        },

        'subscribeService.getSubTopic' : {
            topic : function() {
                subscribeService.getSubTopic(user_id, this.callback);
            },
            'getSubTopic success' : function(err, result, user_topic) {
                assert.equal(result.status, 'success');
                assert.equal(user_topic.user_id, user_id);
            },
            //add teardown to remove just added one
            teardown: function(){
                //TODO
                /*subscribeService.delete(user_id, function(err, affectedRow){
                    assert.equal(1, affectedRow);
                });*/
            }
        }
    }
}).addBatch({
    'subscribeService.subscribeTopic: invalidate param' : {
        topic : function() {
            subscribeService.subscribeTopic('invalidate param', filter, this.callback);
        },
        'subscribe failure' : function(err, result, filter) {
            assert.equal(result.status, 'failed');
        }
    }
}).export(module);